package com.xk.meeting.controller;

import com.google.gson.Gson;
import com.xk.meeting.entityutils.AjaxBean;
import com.xk.meeting.entityutils.PageBean;
import com.xk.meeting.entityutils.DateTime;
import com.xk.meeting.service.ApplyService;
import com.xk.meeting.service.ApplyServiceImpl;
import com.xk.meeting.utils.UtilHelper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

@WebServlet("/applyDisplay")
public class ApplyDisplayServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf8");
        PrintWriter out = response.getWriter();
        String mid = request.getParameter("id");
        HttpSession session = request.getSession();
        DateTime datetime = (DateTime)session.getAttribute("datetime");
        ApplyService applyService = new ApplyServiceImpl();
        Map<String, PageBean> pageBeanMap = null;
        /*if (datetime != null){*/
            pageBeanMap = applyService.getPageBean(Integer.parseInt(mid),datetime);
        /*}else {
            System.out.println("session");
            DateTime dateTime = UtilHelper.createDateTime(0,request);
            pageBeanMap = applyService.getPageBean(Integer.parseInt(mid),dateTime);
        }*/

        AjaxBean ajaxBean = new AjaxBean();
        ajaxBean.setDateTime(datetime);
        ajaxBean.setMap(pageBeanMap);

        /*System.out.println(ajaxBean);*/


        Gson gson = new Gson();
        String json = gson.toJson(ajaxBean);

        out.print(json);


    }
}
